﻿#include "EditorWelcomePageViewModel.h"

#include "Framework/Editor.h"

#include "Project/ProjectWindows.h"
#include "Asset/EngineDefaultPackage.h"

void REditorWelcomePageViewModel::BindModel(TSharedObjectPtr<REditorPageModel> InModel)
{
    Super::BindModel(InModel);
    Model= InModel;

    Icon= REngineDefaultPackage::Get()->GetEngineIcon();
}

TSharedObjectPtr<RTexture2D> REditorWelcomePageViewModel::GetIcon() const
{
    return Icon;
}

CString REditorWelcomePageViewModel::GetTitle() const
{
    return U"欢迎";
}

void REditorWelcomePageViewModel::NewProject()
{
    WHE::OpenProjectCreateWindow();
}

void REditorWelcomePageViewModel::OpenProject()
{
    WHE::ImportExistProjectWithFileDialog();
}

int64_t REditorWelcomePageViewModel::GetRecentProjectNum() const
{
    int64_t Num= REditor::Get()
        ->CurrentSetting.HistoryProjectInfos.Num();
    
    return Num>5?5:Num;
}

CString REditorWelcomePageViewModel::GetRecentProjectName(int64_t Index) const
{
    return REditor::Get()
        ->CurrentSetting.HistoryProjectInfos[Index].Name;
}

CString REditorWelcomePageViewModel::GetRecentProjectPath(int64_t Index) const
{
    return REditor::Get()
        ->CurrentSetting.HistoryProjectInfos[Index].Path;
}

void REditorWelcomePageViewModel::OpenRecentProject(int64_t Index)
{
    WHE::OpenProjectWithErrorMessageBox(
        REditor::Get()
        ->CurrentSetting.HistoryProjectInfos[Index].Path);
}
